
const BASE_URL = 'http://localhost:8080/api/v1';

const request = function ({ type, url, data, dataType, success }) {
    // 如果是FormData对象，需要设置processData为false，contentType为false
    const isFormData = (data instanceof FormData);
    const token = window.localStorage.getItem('bignew_token');
    $.ajax({
        headers: {
            Authorization: token
        },
        type,
        url: BASE_URL + url,
        data,
        dataType,
        processData: isFormData ? false : true,
        contentType: isFormData ? false : 'application/x-www-form-urlencoded',
        success: function (response) {
            success(response)
        },
        error: function (jqXHR, textStatus) {
            if (jqXHR.status === 403) {
                window.location.href = './login.html'
            } else if (jqXHR.statu === 400) {
                alert(jqXHR.responseJSON.msg)
            }
        }
    });

}

// 删除封装
// function deleteCategory(id) {
//     if (confirm('你确定要删除吗')) {
//         request({
//             type: "post",
//             url: '/admin/category/delete',
//             data: { id },

//             success: function (response) {
//                 if (response.code === 204) {
//                     alert('删除成功')
//                     //更新数据
//                     getCategory()
//                 }
//             }
//         })
//     }
// }

